package vo;


import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 列表数据返回对象
 *
 * @author zhanglinfeng
 * @date 2023-05-17 11:59:26
 */
public class PageVO<T> {
    @ApiModelProperty("总页数")
    private Integer totalPage;
    @ApiModelProperty("页码")
    private Integer page;
    @ApiModelProperty("总条数")
    private Integer totalCount;
    @ApiModelProperty("数据列表")
    private List<T> dataList;
    @ApiModelProperty("状态统计")
    private StatusCountVO statusCount;
    @ApiModelProperty("查询条数")
    private Integer limit;
    @ApiModelProperty("跳过条数")
    private Integer offset;

    public PageVO() {
        this.dataList = new ArrayList<>();
    }

    public PageVO(int page, int totalCount, int limit) {
        this.dataList = new ArrayList<>();
        this.page = page;
        this.totalCount = totalCount;
        this.limit = limit;
        this.offset = (page - 1) * limit;
        int mod = totalCount % limit;
        this.totalPage = mod == 0 ? totalCount / limit : totalCount / limit + 1;
        if (page > totalPage) {
            this.page = totalPage;
        }
    }

    public PageVO(int page, int limit, Map<String, Integer> countMap, String currentStatus, List<String> statusList) {
        this.dataList = new ArrayList<>();
        this.page = page;
        this.limit = limit;
        this.offset = (page - 1) * limit;
        this.statusCount = new StatusCountVO(countMap, currentStatus, statusList);
        this.totalCount = statusCount.getCurrentStatusCount();
        int mod = totalCount % limit;
        this.totalPage = mod == 0 ? totalCount / limit : totalCount / limit + 1;
        if (page > totalPage) {
            this.page = totalPage;
        }
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public StatusCountVO getStatusCount() {
        return statusCount;
    }

    public void setStatusCount(StatusCountVO statusCount) {
        this.statusCount = statusCount;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    @Override
    public String toString() {
        return "PageVO{" +
                "totalPage=" + totalPage +
                ", page=" + page +
                ", totalCount=" + totalCount +
                ", dataList=" + dataList +
                ", statusCount=" + statusCount +
                ", limit=" + limit +
                ", offset=" + offset +
                '}';
    }
}
